﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HuynhQuangWebsite.Models;
using THS.HtmlHelpers;

namespace HuynhQuangWebsite.Controllers
{
    public class Dich_vuController : BaseController
    {
        //
        // GET: /ServicePage/
        huynhquangco_websiteEntities ctx = new huynhquangco_websiteEntities();
        public int PageSize = 6;
        public ActionResult Danh_sach(int page = 1)
        {
            var model = new HomeListViewModel();
            IList<Service> services = ctx.Services.Where(p=>p.ServiceIsVisible).OrderBy(p=>p.ServiceIsTypical).ToList();
            model.ServiceList = services.Skip((page-1) * PageSize).Take(PageSize).ToList();
            model.ServiceInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = services.Count() };
            model.ServiceAttributeList = ctx.ServiceAttributes.ToList();
            //get customers
            IList<Customer> customers = ctx.Customers.Where(p => p.CustomerTypical).Take(5).ToList();
            model.CustomerList = customers;
            return View(model);
        }
        public ActionResult Chi_tiet(int id)
        {

            var model = new DetailsListViewModel();
            Service service = ctx.Services.Where(p => p.ServiceID == id).SingleOrDefault();
            model.CurrentService = service;
            model.FlagID = service.ServiceID;
            //get top recent project
            IList<Project> projectList = ctx.Projects.OrderByDescending(p => p.ProjectStartDate).Take(5).ToList();
            model.ProjectList = projectList;
            return View(model);
        }
        public ActionResult Paging(int page = 1)
        {
            var model = new HomeListViewModel();
            IList<Service> services = ctx.Services.Where(p => p.ServiceIsVisible).OrderBy(p => p.ServiceIsTypical).ToList();
            model.ServiceList = services.Skip((page-1) * PageSize).Take(PageSize).ToList();
            model.ProjectInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = services.Count() };
            model.ServiceAttributeList = ctx.ServiceAttributes.ToList();
                return PartialView("UCServiceList", model);
           
        }
        public ActionResult ShowCustomer(int id)
        {
            Customer cust = ctx.Customers.Where(p => p.CustomerID == id).SingleOrDefault();
            ViewData["customer"] = cust;
            return PartialView("UCCustomerList");
        }
    }
}
